import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/auto_makers/shop_home/order_details/order_info.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///已报价
class HavePrice extends StatefulWidget {
  @override
  _HavePriceState createState() => _HavePriceState();
}

class _HavePriceState extends State<HavePrice> {
  List<String> typeList = ["原厂原包","品牌","拆车","OEM"];
  bool isShow = false;//默认隐藏
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: (){
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        backgroundColor: YTStyle.bgColor,
        appBar: AppBar(
          elevation:0,
          centerTitle: true,
          backgroundColor: Colors.white,
          title: Text("已报价",style: TextStyle(color: Color(0xff323232),fontSize: setSp(18),fontWeight: FontWeight.w600),maxLines: 1,overflow: TextOverflow.ellipsis,),
          leading: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: (){
              Navigator.pop(context);
            },
            child: Row(
              children: [
                Container(
                    margin: EdgeInsets.only(left: setWidth(15)),
                    width: setWidth(10),
                    height: setWidth(17),
                    child: Image.asset("assets/images/return.png",fit: BoxFit.cover,)
                ),
              ],
            ),
          ),
          actions: [
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: (){
              },
              child: Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(right: setWidth(15)),
                    child: Text("修改",style: TextStyle(color: YTTheme.theme,fontSize: setSp(16),fontWeight: FontWeight.w600),maxLines: 1,overflow: TextOverflow.ellipsis,),
                  ),
                ],
              ),
            )
          ],
        ),
        body: CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: OrderInfo(),
            ),
            SliverToBoxAdapter(
              child: Container(
                padding: EdgeInsets.only(bottom: setWidth(10),top: setWidth(10)),
                color: Colors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    link(image: "blue_kefu.png",title: "在线联系",phone: "10086"),
                    link(image: "blue_phone_link.png",title: "电话联系",phone: "10086"),
                  ],
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: setWidth(15)),
                padding: EdgeInsets.only(top: setWidth(18),left: setWidth(15),bottom: setWidth(13)),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(bottom:BorderSide(color: Color(0xffF0F0F0),width: setWidth(0.5)) )
                ),
                child: Text("询价信息",style: TextStyle(color: Color(0xff323232),fontSize: setSp(15),fontWeight: FontWeight.w600),),
              ),
            ),
            SliverList(delegate: SliverChildBuilderDelegate((context,index){
              return _listItem();
            },
              childCount: 3,
            )),
            //放弃列表
            SliverList(
                delegate: SliverChildBuilderDelegate(
                      (context, index) {
                    return _listItem();
                  },
                  childCount: isShow?(typeList.length >0 ? typeList.length:0):0,
                )),
            //隐藏显示
            SliverToBoxAdapter(
              child: GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: (){
                  setState(() {
                    isShow = !isShow;
                  });
                },
                child: Container(
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(bottom: setWidth(12)),
                  padding: EdgeInsets.only(
                      top: setWidth(12),
                      bottom: setWidth(12)),
                  color: Colors.white,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                        child: Text(
                          isShow?"隐藏未报价的${typeList.length-1}个商品":"已隐藏未报价的${typeList.length-1}个商品",
                          style: TextStyle(
                              color: Color(0xff989898),
                              fontSize: setSp(14)),
                        ),
                      ),

                      Container(
                        margin: EdgeInsets.only(left: setWidth(6),right: setWidth(6)),
                        child: Text(
                          isShow?"收起": "展开",
                          style: TextStyle(
                              color: Color(0xff989898),
                              fontSize: setSp(14),
                              fontWeight: FontWeight.w600),
                        ),
                      ),
                      SizedBox(width: setWidth(12),
                        height: setWidth(6),
                        child: Image.asset(isShow?"assets/images/shouqi.png":"assets/images/zhankai.png",width: setWidth(12),
                          height: setWidth(6),fit: BoxFit.cover,),
                      ),

                    ],
                  ),
                ),
              ),
            ),

            //结算信息
            SliverToBoxAdapter(
              child: settlementInfo(price:"1259.00",serve: "3280.00",sum: "1259.00"),
            ),
            SliverToBoxAdapter(
              child: SizedBox(
                height: setWidth(30),
              ),
            ),

          ],
        ),

      ),
    );
  }

  Widget _listItem() {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.all(setWidth(15)),
      margin: EdgeInsets.only(bottom: setWidth(12)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: setWidth(90),
                width: setWidth(90),
                decoration: BoxDecoration(
                    color: Color(0xffC4C4C4),
                    borderRadius: BorderRadius.circular(6)
                ),
              ),
              SizedBox(
                width: setWidth(10),
              ),
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      child: Text("前挡泥板-右后翼子板",style: TextStyle(color: Color(0xff323232),fontSize: setSp(15)),maxLines: 2,overflow: TextOverflow.ellipsis,),
                    ),
                    SizedBox(
                      height: setWidth(5),
                    ),
                    Container(
                      child: Text("零件编号：50260TJFJ01",style: TextStyle(color: Color(0xff989898),fontSize: setSp(14)),maxLines: 2,overflow: TextOverflow.ellipsis,),
                    ),
                    SizedBox(
                      height: setWidth(19),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          child: Text("我的报价",style: TextStyle(color: Color(0xff323232),fontSize: setSp(12))),
                        ),
                        SizedBox(
                          width: setWidth(5),
                        ),
                        Expanded(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              RichText(
                                  maxLines: 1,overflow: TextOverflow.ellipsis,
                                  text: TextSpan(
                                children: [
                                  TextSpan(
                                    text: "￥",style: TextStyle(color: YTTheme.theme,fontSize: setSp(12),fontWeight: FontWeight.w600),

                                  ),
                                  TextSpan(
                                    text: "5895.00",style: TextStyle(color: YTTheme.theme,fontSize: setSp(14),fontWeight: FontWeight.w600),

                                  ),

                                ]
                              )),

                              Container(
                                child: Text("x1",style: TextStyle(color: Color(0xff323232),fontSize: setSp(14))),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: setWidth(35),
                    ),

                  ],
                ),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: setWidth(6)),
                    child: Text("属性:",style: TextStyle(color: Color(0xff666666),fontSize: setSp(14)),),
                  )
                ],
              ),
              SizedBox(
                width: setWidth(5),
              ),
              //属性
              Expanded(
                  child:Container(
                    child: Wrap(
                      spacing: setWidth(5),
                      runSpacing: setWidth(5),
                      children: typeList.asMap().map((key, value){
                        return MapEntry(key, typeItem(key,value));
                      }).values.toList(),
                    ),
                  )),
              //撤回
              GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: (){
                },
                child: Container(
                  margin: EdgeInsets.only(top: setWidth(6)),
                  child: Row(
                    children: [
                      Container(
                        width: setWidth(13),
                        height: setWidth(14),
                        child: Image.asset("assets/images/fangqi.png",fit: BoxFit.cover,),
                      ),
                      SizedBox(
                        width: setWidth(3),
                      ),
                      Container(
                        child: Text("撤回",style: TextStyle(color: Color(0xff323232),fontSize: setSp(13)),),
                      ),
                    ],
                  ),
                ),
              )
            ],
          )

        ],
      ),

    );
  }

  //选择属性
  Widget typeItem(int index,String title){
    return Container(
      padding: EdgeInsets.only(top: setWidth(6),bottom: setWidth(6),left: setWidth(11),right: setWidth(11)),
      decoration: BoxDecoration(
          color: Color(0xffF5FFFF),
          border: Border.all(color: YTTheme.theme,width: setWidth(0.5)),
          borderRadius: BorderRadius.circular(2)
      ),
      child: Text(title,style: TextStyle(color: YTTheme.theme,fontSize: setSp(14)),),
    );
  }
}
